package com.ag.utils;

import java.util.Arrays;

import org.apache.commons.lang.StringUtils;
/**
 * @author <a href="mailto:rplees.i.ly@gmail.com">rplees</a>
 * date 2010-04-06
 * {@code} 一些常用的数组有关的帮助方法
 */
public class ArrayUtils {
	
	public static Number max(Number... ns) {
		Arrays.sort(ns) ;
		return ns[ns.length - 1] ;
	}
	public static Number min(Number... ns) {
		Arrays.sort(ns) ;
		return ns[0] ;
	}
	
	public static Integer[] convStringToInteger(String[] split, boolean ignore) {
		if(split == null) return null;
		
		Integer[] is = new Integer[split.length];
		for(int i = 0; i< split.length; i ++) {
			String s = split[i];
			if(StringUtils.isEmpty(s)) {
				if(ignore) continue;
			}
			
			try {
				Integer in = Integer.parseInt(s);
				is[i] = in;
			} catch (Exception e) {
				if(! ignore) {
					throw e;
				}
			}
		}
		
		return is;
	}
}
